<?php
//No direct access
defined('_JEXEC') or die('Restricted access');

jimport('joomla.application.component.view');

class OwnserviceViewTransferHistories extends JView
{
	function display($tpl=null) {

		global $mainframe;

		//Initialize variables
		$document	= & JFactory::getDocument();
		$user			= & JFactory::getUser();
		$ownuser	= & Ownservice::getUser();
		$params 	= & $mainframe->getParams('com_ownservice');
		
		//Check access
		if($user->gid < 25) {
			if ( !(Ownservice::checkAccess('history', 'manage')) ) {
				JError::raiseWarning(500, JText::_('ALERTNOTAUTH') );
				$mainframe->redirect( 'index.php?option=com_ownservice');
			}
		}

		if($this->getLayout() == 'transferdate')
		{
			$this->_displaytransferdate($tpl);
			return;
		}

		if($this->getLayout() == 'details')
		{
			$this->_displaydetails($tpl);
			return;
		}

		if($this->getLayout() == 'alldetails')
		{
			$this->_displayalldetails($tpl);
			return;
		}

		//add css to document
		$document->addStyleSheet(JURI::base().'components/com_ownservice/assets/css/style.css');
		$document->addStyleSheet(JURI::base().'components/com_ownservice/assets/css/nav.css');
		//add java script to document
		$document->addScript(JURI::base().'components/com_ownservice/assets/js/ownservice.js');

		//get data from the model
		$rows = $this->get('Data');


		// Date from and to
		$uts			=  mktime(date("H"), date("i"), date("s"), date("n"), date("d")-10, date("Y"));
		$dateform	= date('Y-m-d', $uts);
		$date			= $dateform.' '.JText::_('OWNSERVICE_TO').' '.date('Y-m-d');

		//assign data to document
		$this->assignRef('date', $date);
		$this->assignRef('rows', $rows);
			
		parent::display($tpl);
	}

	function _displaytransferdate($tpl)
	{
		global $mainframe;

		//Initialize variables
		$document	= & JFactory::getDocument();
		$user			= & JFactory::getUser();
		$ownuser	= & Ownservice::getUser();
		$params 	= & $mainframe->getParams('com_ownservice');

		$selectdate  =JRequest::getVar('date', date('Y-m-d'), 'post');

		//add css to document
		$document->addStyleSheet(JURI::base().'components/com_ownservice/assets/css/style.css');
		$document->addStyleSheet(JURI::base().'components/com_ownservice/assets/css/nav.css');
		$document->addStyleSheet(JURI::base().'components/com_ownservice/assets/css/icon.css');
		//add java script to document
		$document->addScript(JURI::base().'components/com_ownservice/assets/js/ownservice.js');

		//get data from the model
		$rows = $this->get('TransferDate');

		//assign data to document
		$this->assignRef('rows', $rows);
		$this->assignRef('selectdate', $selectdate);
		$this->assignRef('params', $params);

		parent::display($tpl);
	}

	function _displaydetails($tpl)
	{
		global $mainframe;

		//Initialize variables
		$document		= & JFactory::getDocument();
		$config			= & JFactory::getConfig();
		$user				= & JFactory::getUser();
		$params 		= & $mainframe->getParams('com_ownservice');

		//get vars
		$session			= JRequest::getVar('session', 0, 'post', 'int');
		$date				= JRequest::getVar('date', '', 'post');

		//add css to document
		$document->addStyleSheet(JURI::base().'components/com_ownservice/assets/css/style.css');
		$document->addStyleSheet(JURI::base().'components/com_ownservice/assets/css/nav.css');
		$document->addStyleSheet(JURI::base().'components/com_ownservice/assets/css/icon.css');
		//add java script to document
		$document->addScript(JURI::base().'components/com_ownservice/assets/js/ownservice.js');

		//get data from the model
		$model	=& $this->getModel();
		$rows		= $this->get('DetailTransfer');

		//assign data to document
		$this->assignRef('rows', $rows);
		$this->assignRef('selectdate', $date);
		$this->assignRef('session', $session);
		$this->assignRef('params', $params);

		parent::display($tpl);
	}

	function _displayalldetails($tpl)
	{
		global $mainframe;

		//Initialize variables
		$document		= & JFactory::getDocument();
		$config			= & JFactory::getConfig();
		$user				= & JFactory::getUser();
		$params 		= & $mainframe->getParams('com_ownservice');

		//get vars
		$session			= JRequest::getVar('session', 0, 'post', 'int');
		$date				= JRequest::getVar('date', '', 'post');

		//add css to document
		$document->addStyleSheet(JURI::base().'components/com_ownservice/assets/css/style.css');
		$document->addStyleSheet(JURI::base().'components/com_ownservice/assets/css/nav.css');
		$document->addStyleSheet(JURI::base().'components/com_ownservice/assets/css/icon.css');
		
		//add java script to document
		$document->addScript(JURI::base().'components/com_ownservice/assets/js/ownservice.js');

		//get data from the model
		$model	=& $this->getModel();
		$rows		= $this->get('AllDetailTransfer');
		//echo '<pre>'; print_r($rows); echo '</pre>';

		//assign data to document
		$this->assignRef('rows', $rows);
		$this->assignRef('selectdate', $date);
		$this->assignRef('session', $session);
		$this->assignRef('params', $params);

		parent::display($tpl);
	}
}